// pages/userCenter/myCarNote/myCarNote.js
const request = require('../../../utils/request')

Page({
  data: {
    currentTab: 0,
    repairList: []
  },

  onLoad: function() {
    this.getRepairList('my_repair_now')
  },
  
  swichNav: function(e) {
    if (this.data.currentTab === e.target.dataset.current) return 

    this.setData({
      currentTab: e.target.dataset.current
    })

    if (this.data.currentTab === 0) {
      this.getRepairList('my_repair_now')
    } else {
      this.getRepairList('my_repair_finish')
    }
  },

  toweixiuIng(e) {
    const type = this.data.currentTab === 0 ? 'BEING' : 'DONE'
    wx.navigateTo({
      url: `../myCarNote/weixiuIng/weixiuIng?id=${e.currentTarget.dataset.id}&type=${type}`,
    })
  },

  toBaoyangDetail: function() {
    wx.navigateTo({
      url: '../myCarNote/baoyang/baoyang',
    })
  },

  toWeixiuDone:function(){
    wx.navigateTo({
      url: '../myCarNote/weixiuDone/weixiuDone',
    })
  },

  //正在修车 
  getRepairList(url){
    wx.showLoading()
    request.get(url)
      .then(res => {
        wx.hideLoading()
        if (res.data && res.data.length) {
          this.setData({
            repairList: res.data
          })
        }
      })
      .catch(error => {
        wx.showToast({
          icon: 'none',
          title: error.msg && error.msg
        })
      })
      .finally(_ => {
        
      })
  },

  onPullDownRefresh: function() {

  },

  onReachBottom: function() {

  },
})